package com.suray.basic.wcs.plc.pojo.oper;

import com.suray.basic.wcs.plc.core.PlcOffset;
import com.suray.basic.wcs.plc.enums.PlcDeviceType;
import com.suray.basic.wcs.plc.enums.Location;
import com.suray.basic.wcs.plc.pojo.DeviceBase;
import com.suray.basic.wcs.utils.Coord;

/**
 * @author shaozn
 * @date 2020/1/22 - 15:23
 * @Description 外形检测
 */
public class ShapeDetectorOper extends DeviceBase {

    private static final PlcOffset RESULT = new PlcOffset(0, null);
    private static final PlcOffset HIGH_TRANS_FINITE = new PlcOffset(1, 8);
    private static final PlcOffset FRONT_TRANS_FINITE = new PlcOffset(1, 9);
    private static final PlcOffset AFTER_TRANS_FINITE = new PlcOffset(1, 10);
    private static final PlcOffset LEFT_TRANSFINITE = new PlcOffset(1, 11);
    private static final PlcOffset RIGHT_TRANSFINITE = new PlcOffset(1, 12);
    private static final PlcOffset SPARE_1 = new PlcOffset(1, 13);
    private static final PlcOffset SPARE_2 = new PlcOffset(1, 14);
    private static final PlcOffset SPARE_3 = new PlcOffset(1, 15);
    private static final PlcOffset HIGH_TYPE = new PlcOffset(2, null);


    /**
     * 外形检测结果 0. 无， 1. 合格 2.不合格
     */
    private int result;
    /**
     * 高超限
     */
    private boolean highTransfinite;
    /**
     * 前超限
     */
    private boolean FrontTransfinite;
    /**
     * 后超限
     */
    private boolean afterTransfinite;
    /**
     * 左超限
     */
    private boolean LeftTransfinite;
    /**
     * 右超限
     */
    private boolean rightTransfinite;
    /**
     * 高度类型
     * 0:无         1:一类高度
     * 2:二类高度   3:三类高度
     */
    private int highType;

    public int getResult() {
        return readPlc(RESULT);
    }

    public boolean isHighTransfinite() {
        return readPlc(HIGH_TRANS_FINITE) == 1;
    }

    public boolean isFrontTransfinite() {
        return readPlc(FRONT_TRANS_FINITE) == 1;
    }

    public boolean isAfterTransfinite() {
        return readPlc(AFTER_TRANS_FINITE) == 1;
    }

    public boolean isLeftTransfinite() {
        return readPlc(LEFT_TRANSFINITE) == 1;
    }

    public boolean isRightTransfinite() {
        return readPlc(RIGHT_TRANSFINITE) == 1;
    }

    public int getHighType() {
        return readPlc(HIGH_TYPE);
    }

    public ShapeDetectorOper(PlcDeviceType plcDeviceType, int startNo, String deviceName, int deviceNo, Coord coord,
                             Location location, Coord lockLocation, long deviceId, Integer gridzMax,
                             Integer gridzRelative, int plcId) {
        super(plcDeviceType, startNo, deviceName, deviceNo, coord, location, lockLocation, deviceId, gridzMax,
                gridzRelative, plcId);
    }
}
